package com.yksj.healthtalk.ui.home;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.net.socket.SmartFoxClient;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.friend.FriendSearchMainActivity;
import com.yksj.healthtalk.utils.FriendHttpUtil;
/**
 * 家园 ---朋友----我的朋友主页
 * @author root
 *
 */
public class FriendListActivity extends BaseFragmentActivity implements OnClickListener{
	
	protected ArrayList<Object> data = new ArrayList<Object>();
	/**
	 * 搜索界面设置数据
*/
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
		setContentView(R.layout.pull_main_friend_group);
		setUpView();
		
		
		Fragment fragment = new MyFriendListFragment();
		FragmentManager manager = getSupportFragmentManager();
		FragmentTransaction transaction = manager.beginTransaction();
		transaction.replace(R.id.frameLayout, fragment);
		transaction.commit();
	}

	/**
	 * 初始化界面
	 */
	public void setUpView() {
		initTitle();
		if(SmartFoxClient.getLoginUserInfo().isDoctor()){
			titleTextV.setText("我的朋友");
		}else{
			titleTextV.setText("我的病友");
		}
		titleRightBtn2.setText("搜索");
		titleLeftBtn.setOnClickListener(this);
		titleRightBtn2.setOnClickListener(this);
		titleRightBtn2.setVisibility(View.VISIBLE);
	}


	/**
	 * 按钮点击监听事件处理
	 * 
	 * @param v
	 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		case R.id.title_right2:
			Intent intent = new Intent();
			intent.putExtra("search_type", 1);
			intent.setClass(this, FriendSearchMainActivity.class);
			startActivityForResult(intent, 0);
			break;
		}
	}
	
	@Override
	protected void onActivityResult(int arg0, int arg1, Intent data) {
		if (data != null && data.hasExtra("mCustomerInfoEntity")) {
			CustomerInfoEntity mCustomerInfoEntity = data.getParcelableExtra("mCustomerInfoEntity");
			Intent intent = new Intent(this,MyFriendSearchActivity.class);
			intent.putExtra("mCustomerInfoEntity", mCustomerInfoEntity);
			intent.putExtra("type", true);
			startActivity(intent);
		}
		super.onActivityResult(arg0, arg1, data);
	}
}
